import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

public class MyConditionSignalRunnableTask implements Runnable {

    private ReentrantLock reentrantLock;

    private Condition condition;

    public MyConditionSignalRunnableTask(ReentrantLock reentrantLock, Condition condition) {

        this.reentrantLock = reentrantLock;

        this.condition = condition;

    }

    @Override

    public void run() {

        try {

            reentrantLock.lock(); // 当前t2节点加到同步队列

            System.out.println(Thread.currentThread().getName() + "lock,拿到锁了");

            try {

                Thread.sleep(20*1000);

            } catch (InterruptedException e) {

                e.printStackTrace();

            }

            System.out.println(Thread.currentThread().getName() + "发出信号");

            condition.signal(); // 通知条件队列中第一个节点,此时条件队列-->加到同步队列,并仍然阻塞

        } finally {

            reentrantLock.unlock(); // 从同步队列中头节点开始找,并unpark

            System.out.println(Thread.currentThread().getName() + "unlock结束");

        }

    }

}
